package com.hlw.hr_man.daoImpl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.hlw.hr_man.Model.DeptModel;
import com.hlw.hr_man.dao.SuDeptDao;
import com.hlw.hr_man.util.JDBCUtil;

import net.sf.json.JSON;
import net.sf.json.JSONObject;


public class SuDeptDaoImpl implements SuDeptDao{
  
	public JSON getDeptByDeptName(String d_name) {
	
		JSONObject dep  = new JSONObject();
		List<DeptModel> dept = new ArrayList<DeptModel>();
		Connection con = JDBCUtil.getConnection();
		StringBuffer sql = new StringBuffer("select dept_name,dept_describe,dept_createtime,dept_id from hr_department where dept_name =?");
		try {
			PreparedStatement pst = con.prepareStatement(sql.toString());
			pst.setString(1, d_name);
			ResultSet rs = pst.executeQuery();
			if(rs.next()){
				DeptModel dm = new DeptModel();
				dm.setDept_name(rs.getString("dept_name"));
				dm.setDept_describe(rs.getString("dept_describe"));
				dm.setDept_createtime(rs.getString("dept_createtime"));
				dm.setDept_id(rs.getInt("dept_id"));
				dept.add(dm);
				dep = JSONObject.fromObject(dm);
				
			
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return dep;
	}

}